home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / treadmil.lua < prev    next >
Text File  |  2004-01-29  |  2KB  |  76 lines

  1. -- treadmill oldschool state machine
  2.  
  3. beginStateMachine()
  4.     
  5.     onMsg("buildMenu", function(msg)
  6.     
  7.         if (repairMenu()) then return end
  8.     
  9.         -- build the pie menu
  10.         clearPieMenu();
  11.         local button ;
  12.         button = addPieMenuButton("Trainieren", "run");
  13.         button.addDescription(ACTIVITY, "run");
  14.         -- button.addIcon("guiIconLibido");
  15.     end )
  16.     
  17.     -- run on tradmill
  18.     onMsg("run", function(msg)
  19.         -- get the game object server
  20.         local gameObjectServer = getGameObjectServer();
  21.         -- get character who initiated this action
  22.         local character = getStateObjectFromID(msg.sender);
  23.         -- if this is broken: abort characters action
  24.         if abortIfBroken(character) then return end;        
  25.         -- walk to the closest action point
  26.         local actionPoint = character.getFreeActionPoint(this, "run");
  27.         if (actionPoint) then
  28.         -- get the walk state object
  29.             local wso = character.walkSO;
  30.             -- create state machine contexts
  31.             local wsoContext = StateMachineContext();
  32.             -- store the action point
  33.             wsoContext.storeData("actionPointName", actionPoint.getName());
  34.             if (wso.walkToActionPoint(actionPoint)) then
  35.                 wso.queueStateMachine("treadmilChar.enter", this, wsoContext);
  36.             else
  37.                 print("no path found");
  38.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  39.             end
  40.         else
  41.             print("no action point found");
  42.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  43.         end
  44.     end )
  45.     
  46.     
  47.     -- repair
  48.     onMsg("repair", function(msg)
  49.     
  50.         print("onMsg repair");
  51.         -- get character who initiated this action
  52.         local character = getStateObjectFromID(msg.sender);
  53.         -- walk to the closest action point
  54.         -- local actionPoint = character.getFreeActionPoint(this, "repair");
  55.         local actionPoint = character.getClosestFreeActionPoint(character, this, {"repair1", "repair2", "repair3"});
  56.         -- get the walk state object
  57.         local wso = character.walkSO;
  58.         if (actionPoint) then
  59.             -- create state machine contexts
  60.             local wsoContext = StateMachineContext();
  61.             -- store the action point
  62.             wsoContext.storeData("actionPointName", actionPoint.getName());
  63.             if (wso.walkToActionPoint(actionPoint)) then
  64.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  65.             else
  66.                 print("no path found");
  67.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  68.             end
  69.         else
  70.             print("no action point found");
  71.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  72.         end
  73.     end )
  74.                         
  75. endStateMachine()
  76.